package com.nowcoder.community.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.management.remote.rmi._RMIConnection_Stub;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Page {
    //当前页码
    private int current=1;
//    显示上限(每页最多显示多少条数据)
    private int limit=10;
//    数据总数
    private int rows;
    //查询路径
    private String path;

    public void setCurrent(int current) {
        if (current>1){

        this.current = current;
        }
    }

    public void setLimit(int limit) {
        if (limit >=1 && limit<=100){

        this.limit = limit;
        }
    }
    public int getOffset(){
        return (current-1)*limit;
    }
    public int getTotal(){
        if(rows%limit==0){
            return rows/limit;
        }else{
            return rows/limit+1;
        }
    }
    public int getFrom(){
        int from = current-2;
        return from<1 ? 1:from;
    }
    public int getTo(){
        int to = current +2;
        return to>getTotal() ? getTotal() : to;
    }
}
